Test Series - Data Structure

Test Number 34/115

Q: What is a dynamic array?
A. A variable size data structure
B. An array which is created at runtime
C. The memory to the array is allocated at runtime
D. An array which is reallocated everytime whenever new elements have to be added
Solution: It is a varying-size list data structure that allows items to be added or removed, it may use a fixed sized array at the back end.
Q:  What is meant by physical size in a dynamic array?
A. The size allocated to elements
B. The size extended to add new elements
C. The size of the underlying array at the back-end
D. The size visible to users
Solution: Physical size, also called array capacity is the size of the underlying array, which is the maximum size without relocation of data.
Q: The number of items used by the dynamic array contents is its __________
A. Physical size
B. Capacity
C. Logical size
D. Random size
Solution: The number of items used by the dynamic array contents is called logical size. Physical size is the size of the underlying array, which is the maximum size without reallocation of data.
Q: How will you implement dynamic arrays in Java?
A. Set
B. Map
C. HashMap
D. List
Solution: ArrayList is used to implement dynamic arrays in Java.
Q: Which of the following is the correct syntax to declare an ArrayList in Java?
A. ArrayList al = new ArrayList();
B. ArrayList al = new ArrayList[];
C. ArrayList al() = new ArrayList();
D. ArrayList al[] = new ArrayList[];
Solution: This is a non-generic way of creating an ArrayList.
Q: Array is divided into two parts in ____________
A. Hashed Array Tree
B. Geometric Array
C. Bounded-size dynamic array
D. Sparse Array
Solution: The first part stores the items of the dynamic array and the second part is reserved for new allocations.
Q: Which of the following is a disadvantage of dynamic arrays?
A. Locality of reference
B. Data cache utilization
C. Random access
D. Memory leak
Solution: Dynamic arrays share the advantage of arrays, added to it is the dynamic addition of elements to the array. Memory can be leaked if it is not handled properly during allocation and deallocation. It is a disadvantage.
Q: What is the time complexity for inserting/deleting at the beginning of the array?
A.  O(1)
B. O(n)
C. O(logn)
D. O(nlogn)
Solution: All the other elements will have to be moved, hence O(n).
Q: Dynamic arrays overcome the limit of static arrays.
A. True
B. False
C. ....
D. ....
Solution: Static arrays have fixed capacity. The capacity must be specified during memory allocation. Dynamic arrays don’t require to specify their capacity during memory allocation. Dynamic arrays have fixed physical size at backend and its capacity increases if required. Thus, Dynamic arrays overcome the limit of static arrays.
Q: The size of the dynamic array is deallocated if the array size is less than _________% of the backend physical size.
A. 30
B.  40
C. 10
D. 20
Solution: The size of the dynamic array is decreased/deallocated if the actual size of the array is less than 30% of the backend physical size. This is used to avoid memory wastage.

You Have Score    /10